$(function(){
    resetPassword=function(){
        
        password=$("#password").val();
        new_password=$("#new_password").val();
        reset_password=$("#reset_password").val();

        flag=true;
        if(password==''){
            $("#password").addClass('error');
            $("#password-error").show();
            $("#password-error").html("不能为空");
            flag=false;
        }
        if(new_password==''){
            $("#new_password").addClass('error');
            $("#new_password-error").show();
            $("#new_password-error").html("不能为空");
            flag=false;
        }
        if(reset_password==''){
            $("#reset_password").addClass('error');
            $("#reset_password-error").show();
            $("#reset_password-error").html("不能为空");
            flag=false;
        }

        if(flag){
            if(new_password==reset_password){
                password=CryptoJS.MD5(password).toString(CryptoJS.enc.Hex);
                $.post("/php/reset-password.php",{password:password,new_password:new_password},function(result){
                    resultObj=JSON.parse(result);
                    switch(resultObj.code){
                        case '2001':
                        layer.msg(resultObj.message);
                            break;
                        case '2002':
                            $("#password").addClass('error');
                            $("#password-error").show();
                            $("#password-error").html(resultObj.message);
                            break;
                        case '2003':
                            $("#new_password").addClass('error');
                            $("#new_password-error").show();
                            $("#new_password-error").html(resultObj.message);
                            break;
                        case '2004':
                            layer.msg(resultObj.message);
                            break;
                        default:break;
                    }
                });
            }else{
                $("#reset_password").addClass('error');
                $("#reset_password-error").show();
                $("#reset_password-error").html("两次密码输入不一致");
                $("#new_password").addClass('error');
                $("#new_password-error").show();
                $("#new_password-error").html("两次密码输入不一致");
            }
        }
    }

    //恢复默认样式
    $("input").click(function(){
        $(this).removeClass('error');
        var val=$(this).attr("id");
        var label_id="#"+val+"-error";
        $(label_id).hide();
    });
    //显示服务端验证信息
    function validate_server(message,code){
        var array=Array("编号","名称");
        var id_array=new Array("#id","#name","#abbreviation","#height",
            "#rooms","#beds","#remarks");
        var error_array=new Array("#id-error","#name-error","#abbreviation-error",
            "#height-error","#rooms-error","#beds-error","#remarks-error");
        switch(code){
            case 1:
                $.each(message, function(e, value) {
                    //alert(id_array[value]);
                    $(id_array[value]).addClass('error');
                    $(error_array[value]).show();
                    $(error_array[value]).html("输入不符合要求");
                });
            break;
            case 2:
                $.each(message, function(e, value) {
                    //alert(id_array[value]);
                    $(id_array[value]).addClass('error');
                    $(error_array[value]).show();
                    $(error_array[value]).html(array[value]+"已存在");
                });
            break;
            default:break;
        }
        return;
    }
});